<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header("location:checklogin.php");
}

{	
  if(isset($_POST['submit']))
  { 
    $loopCntDetail = 0;
    while($loopCntDetail < count($_POST['issueNo']))
    {
     	  $issueNo      = isset($_POST['issueNo'][$loopCntDetail]) ? $_POST['issueNo'][$loopCntDetail] : "";
        //$issueDate    = $_POST['curDateYear']."-".$_POST['curDateMonth']."-".$_POST['curDateDay'];
        $issueDate = isset($_POST['curDate'][$loopCntDetail*3+2]) ? 
	                      $_POST['curDate'][$loopCntDetail*3+2]['Year']."-".$_POST['curDate'][$loopCntDetail*3+1]['Month']."-".$_POST['curDate'][$loopCntDetail*3]['Day']: '0000-00-00';
        
     	  $partyId      = isset($_POST['partyId'][$loopCntDetail]) ? $_POST['partyId'][$loopCntDetail] : 0;
   	    $consRecived  = isset($_POST['consRecived'][$loopCntDetail]) ? $_POST['consRecived'][$loopCntDetail] : 0;
   	    
   	    if($partyId > 0)
   	    {
          $insertGodown = "INSERT INTO godownissue	(issueNo,issueDate,partyId,consRecived)
	                                            VALUES('".$issueNo."','".$issueDate."',".$partyId.",".$consRecived.")";
	        $insertGodownRes = mysql_query($insertGodown);
	    
	        if(!$insertGodownRes)
	        {
	        	echo "data not Inserted ".mysql_error();
	        }
	        else
          {
            header("location:godownIssues.php");
          }
          
        }
        $loopCntDetail ++;
    }
  }
 $partyArray = array();
 $k=0;
 
 $party = "SELECT partyId,name
             FROM party";
 $partyRes = mysql_query($party);
 while($partyRow = mysql_fetch_array($partyRes))
 {
 	$partyArray['partyId'][$k] = $partyRow['partyId'];
 	$partyArray['name'][$k]    = $partyRow['name'];
 	$k++;
 }
  include("./bottom.php");
  $smarty->assign('partyArray',$partyArray);
  $smarty->display("godownIssues.tpl");
}
?>